// src/router/index.js
import { createRouter, createWebHistory } from "vue-router";
import VueCookies from "vue-cookies";
// import Home from '../views/Home.vue';
// import About from "../views/About.vue";

const routes = [
  {
    path: "/home",
    name: "Home",
    component: () => import("../views/Home.vue"),
  },
  {
    path: "/",
    name: "框架页",
    component: () => import("../views/Framework.vue"),
    redirect: "/blog/list",
    children: [
      {
        path: "/blog/test",
        name: "博客管理1",
        component: () => import("../views/blog/Test.vue"),
      },
      {
        path: "/blog/list",
        name: "博客管理",
        component: () => import("../views/blog/BlogList.vue"),
      },
      {
        path: "/blog/category",
        name: "分类管理",
        component: () => import("../views/blog/BlogCategory.vue"),
      },
      {
        path: "/special/list",
        name: "专题管理",
        component: () => import("../views/special/SpecialList.vue"),
      },
      {
        path: "/settings/my",
        name: "个人信息",
        component: () => import("../views/settings/myInfo.vue"),
      },
      {
        path: "/settings/user",
        name: "博客成员",
        component: () => import("../views/settings/TeamUser.vue"),
      },
      {
        path: "/settings/sysInfo",
        name: "系统设置",
        component: () => import("../views/settings/SysInfo.vue"),
      },
      {
        path: "/recovery/list",
        name: "回收站",
        component: () => import("../views/recovery/RecoveryList.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  const userInfo = VueCookies.get("userInfo");
  if (!userInfo && to.path != "/login") {
    router.push("/login");
  }
  next();
});
export default router;
